import 'dart:io';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/rendering.dart';

class FlutterOpenglLongView extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    if (Theme.of(context).platform == TargetPlatform.android) {
      // MethodChannel('flutter_test_opengl_plugin').invokeMethod('createTextureView');
      return PlatformViewLink(
        viewType: 'opengl_view_long',
        surfaceFactory: (BuildContext context, PlatformViewController controller) {
          return AndroidViewSurface(
            controller: controller as AndroidViewController,
            gestureRecognizers: const <Factory<OneSequenceGestureRecognizer>>{},
            hitTestBehavior: PlatformViewHitTestBehavior.opaque,
          );
        },
        onCreatePlatformView: (PlatformViewCreationParams params) {
          return PlatformViewsService.initSurfaceAndroidView(
            id: params.id,
            viewType: 'opengl_view_long',
            layoutDirection: TextDirection.ltr,
            creationParams: {},
            creationParamsCodec: StandardMessageCodec(),
          )
            ..addOnPlatformViewCreatedListener(params.onPlatformViewCreated)
            ..create();
        },
      );
    } else if(Theme.of(context).platform == TargetPlatform.iOS){
      return const UiKitView(
          viewType: 'opengl_view_long',
          layoutDirection: TextDirection.ltr,
          creationParams: {},
          creationParamsCodec: StandardMessageCodec());
    } else if(Theme.of(context).platform == TargetPlatform.macOS){
      return const AppKitView(
          viewType: 'opengl_view_long',
          layoutDirection: TextDirection.ltr,
          creationParams: {},
          creationParamsCodec: StandardMessageCodec());
    }
    return Text('Android only');
  }
}
